package com.usian.article.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.admin.AuthorControllerApi;
import com.usian.article.service.AuthorService;
import com.usian.article.service.impl.AuthorServiceImpl;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/author")

public class AuthorController implements AuthorControllerApi {
    @Autowired
    private AuthorServiceImpl service;
    @Override
    @GetMapping("findByUserId/{id}")
    public ApAuthor findByUserId(@PathVariable Integer id) {
        return service.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(id!=null,ApAuthor::getUserId,id));
    }

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        if (apAuthor==null)return  service.errorParam;
        service.save(apAuthor);
        return ResponseResult.okResult(apAuthor);
    }

    @GetMapping("/one/{id}")
    @Override
    public ApAuthor findById(@PathVariable("id") Integer id) {
        return service.getById(id);
    }
}
